<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
</head>
<body>

<script src="../vue.js"></script>
<script>
  /*/ 事件中心
  const vm = new Vue();
  // 订阅消息
  vm.$on('dataChange', () => {
    console.log('dataChange')
  })

  // 订阅消息
  vm.$on('dataChange', () => {
    console.log('dataChange')
  })

  // 发布消息
  vm.$emit('dataChange')*/

  class EventEmitter {
    constructor() {
      this.subs = Object.create(null)
    }

    $on(eventType, handler) {
      const events = this.subs[eventType] = this.subs[eventType] || []
      events.push(handler);
    }

    $emit(eventType) {
      this.subs[eventType]?.forEach(handler => handler())
    }
  }
  const em = new EventEmitter();
  em.$on('click', () => console.log('click1'))
  em.$on('click', () => console.log('click2'))
  em.$emit('click')
</script>
</body>
</html>